/** 
 * Copyright (C) 2012 Foxit Corporation. 
 * All Rights Reserved.
 *
 * The following code is copyrighted and contains proprietary information and trade secrets of Foxit Corporation. 
 * You can only redistribute files listed below to customers of your application, under a written SDK license agreement with Foxit. 
 * You cannot distribute any part of the SDK to general public, even with a SDK license agreement. 
 * Without SDK license agreement, you cannot redistribute anything.
 *
 * @file	fgsepubbase.h
 * @brief	Header file for EPUB Base module.<br>
 * @details	This module offers:<br>
 *			1. Definitions of custom encryption and decryption.<br>
 *			2. Definitions of custom security handler.<br>
 *			3. Definitions of custom ePub package.<br>
 *
 * @note	If you want to purchase Foxit PDF SDK license and use ANY of the following functions, please
 *			request for enabling Base Data module explicitly. 
 */

/** 
 * @addtogroup FGSEPUB EPUB Base
 * @brief Definitions and Methods in this module are included in fgsepubbase.h.
 */

/**@{*/
#ifndef __FGSEPUBBASE__
#define __FGSEPUBBASE__

#include "../dp/fgsdp.h"

#if defined(__cplusplus)
extern "C" {
#endif

/** @brief ePub security reference type. */
typedef const struct __FGSEPUBSecurity * FGSEPUBSecurityRef;

/** @brief ePub package reference type. */
typedef const struct __FGSEPUBPackage * FGSEPUBPackageRef;

/** @brief ePub file reference type. */
typedef const struct __FGSEPUBFile * FGSEPUBFileRef;

/** 
 * @name FGSEPUB Enumeration Types
 */
/**@{*/
/**
 * @brief Enum definitions for Cascading Style Sheets.
 */
enum {
	/** agent css style. */
    kFGSEPUBCSSStyleAgent     = 0,
	/** user css style. */
    kFGSEPUBCSSStyleUser      = 1,
    /** author css style. */
    kFGSEPUBCSSStyleAuthor    = 2
};
/** @brief Alias of enumeration for Cascading Style Sheets. */
typedef UInt32 FGSEPUBCSSStyle;
/** @}*/

/** 
 * @brief Interfaces for custom encryption and decryption. 
 */
typedef struct __FGSEPUBCryptoHandler {
	/** @brief The size of the data structure. It must be set to <I>sizeof</I>(::FGSEPUBCryptoHandler). */
	UInt32                  size;
	/** @brief The user-supplied data. */
	void *					clientData;
	/**
	 * @brief A callback function can be called when to release everything.
	 *
	 * @param[in] clientData			The user-supplied data.
     *
	 * @return None.
	 */
	void					(*release)(void *clientData);

	/**
	 * @brief Get encrypted data size for a source data block.
	 * 
	 * @param[in] clientData		The user-supplied data.
	 * @param[in] fileName			The path of file in ePub file.
	 * @param[in] drmVersion		The DRM used version.
	 * @param[in] appVersion		The application version.
	 * @param[in] srcFileStream     Reference to a file stream.
     *
	 * @return                      The encrypted data size.
	 */
    UInt32                  (*encryptGetSize)(void *clientData, CFStringRef fileName,
                                          CFStringRef drmVersion, CFStringRef appVersion, FGSFileStreamInRef srcFileStream);
        
	/**
	 * @brief A callback function used to encrypt a source data block.
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @param[in] fileName			The path of file in ePub.
	 * @param[in] drmVersion		The DRM used version.
	 * @param[in] appVersion		The application version.
	 * @param[in] srcFileStream		Source file stream to be encrypted.
	 * @param[out] dstFileStream    File stream for the result of the encryption.
     *
	 * @return                      ::kFGSErrorSuccess means success.<br>
	 *                              For more definitions please see enum definitions <b>FGSErrorRet</b>.
	 */
    FGSErrorRet              (*encrypt)(void *clientData, CFStringRef fileName,
                                   CFStringRef drmVersion, CFStringRef appVersion,
                                   FGSFileStreamInRef srcFileStream, FGSFileStreamOutRef dstFileStream);

	 /**
	  * @brief Get decrypted data size for a source data block.
	  * 
	  * @param[in] clientData		The user-supplied data.
	  * @param[in] fileName			The path of file in ePub.
	  * @param[in] drmVersion		The DRM used version.
	  * @param[in] appVersion		The application version.
	  * @param[in] srcFileStream	The	source file stream to be decrypted.
      *
	  * @return                     The decrypted data size.
	  */
    UInt32                  (*decryptGetSize)(void *clientData, CFStringRef fileName,
                                          CFStringRef drmVersion, CFStringRef appVersion, FGSFileStreamInRef srcFileStream);
    
	 /**
	  * @brief A callback function used to encrypt a source data block.
	  * 
	  * @param[in] clientData		The user-supplied data.	
	  * @param[in] fileName			The path of file in ePub.
	  * @param[in] drmVersion		The DRM used version.
	  * @param[in] appVersion		The application version.
	  * @param[in] srcFileStream	The source file stream to be decrypted.
	  * @param[out] dstFileStream	The file stream for the result of the decryption.
      *
	  * @return                     ::kFGSErrorSuccess means success.<br>
	  *                             For more definitions please see enum definitions <b>FGSErrorRet</b>.
	  */
    FGSErrorRet              (*decrypt)(void *clientData, CFStringRef fileName,
                                   CFStringRef drmVersion, CFStringRef appVersion,
                                   FGSFileStreamInRef srcFileStream, FGSFileStreamOutRef dstFileStream);
} FGSEPUBCryptoHandler;

/**
 * @brief Interfaces for security handler.
 */
typedef struct __FGSEPUBSecurityHander {
	/** @brief The size of the data structure. It must be set to <I>sizeof</I>(::FGSEPUBSecurityHander). */
	UInt32                  size;
	/** @brief The user-supplied data. */	
	void *					clientData;
   /**
	* @brief A callback function can be called when to release everything.
	*
	* @param[in] clientData			The user-supplied data.
	* @return                       None.
	*/
	void					(*release)(void *clientData);    
   /**
	* @brief A callback function can be called to get a crypto handler.
	*
	* @param[in] clientData			The user-supplied data.
    *
	* @return                       The crypto handler if it success,otherwise NULL.
	*/
	FGSEPUBCryptoHandler *  (*getCryptoHandler)(void *clientData);    
} FGSEPUBSecurityHander;

/** 
 * @name FGSEPUB Enumeration Types
 */
/**@{*/
/**
 * @brief Enum definitions for encryption info.
 */
enum {
	/** The filter of the encryption. */
    kFGSEPUBEncryptInfoFilter     = 1,
	/** The subfilter of the encryption. */
    kFGSEPUBEncryptInfoSubFilter  = 2,
	/** The issuer of the encryption. */
    kFGSEPUBEncryptInfoIssuer     = 3,
	/** The creator of the encryption. */
    kFGSEPUBEncryptInfoCreator    = 4,
	/** The flowcode of the encryption. */
    kFGSEPUBEncryptInfoFlowCode   = 5,
	/** The order of the encryption. */
    kFGSEPUBEncryptInfoOrder      = 6,
	/** The user of the encryption. */
    kFGSEPUBEncryptInfoUser       = 7,
	/** The service url of the encryption */
    kFGSEPUBEncryptInfoServiceURL = 8,
	/** The version of the encryption. */
    kFGSEPUBEncryptInfoVersion    = 9,
	/** The algorithm of the encryption. */
    kFGSEPUBEncryptInfoAlgorithm  = 10
};
/** @brief Alias of enumeration for encryption info. */
typedef UInt32 FGSEPUBEncryptInfo;

/**
 * @brief Enum definitions for encryption status.
 */
enum {
	/** The unknown encrypt status. */ 
    kFGSEPUBEncryptStatusUnKnown               = -1,
	/** The status that not encrypted. */ 
    kFGSEPUBEncryptStatusUnEncryted            = 0,
	/** The status of encryption un_standard password. */ 
    kFGSEPUBEncryptStatusUnStandardPassword    = 1,
};
/** @brief Alias of enumeration for encryption status. */
typedef SInt32 FGSEPUBEncryptStatus;
/** @}*/

/**
 * @brief Interfaces for custom ePub package handler.
 */
typedef struct __FGSEPUBPackageHandler {
	/** @brief The size of the data structure. It must be set to <I>sizeof</I>(::FGSEPUBPackageHandler). */
	UInt32                  size;
	/** @brief The user-supplied data. */
	void *					clientData;
   /**
	* @brief A callback function can be called when to release everything.
	*
	* @param[in] clientData			The user-supplied data.
    *
	* @return                       None.
	*/
	void					(*release)(void *clientData);
	/**
	 * @brief A function used to load an ePub file
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @param[in] ePubFileStream	Stream of the source epub file.
     *
	 * @return                      ::kFGSErrorSuccess means success.<br>
	 *                              For more definitions please see enum definitions <b>FGSErrorRet</b>.
	 */
    FGSErrorRet			    (*loadEpub)(void *clientData, FGSFileStreamInRef ePubFileStream);
   /**
	* @brief A function used to unload an ePub file.
	*
	* @param[in] clientData			The user-supplied data.
    *
	* @return                       None.
	*/
    void					(*unloadEpub)(void *clientData);
	/**
	 * @brief A function used to encryption status.
	 * 
	 * @param[in] clientData		The user-supplied data.
     *
	 * @return                      0: unencrypted, -1: unknown or error, 1: standard password
	 */
    FGSEPUBEncryptStatus      (*getEncryptionStatus)(void *clientData);
	/**
	 * @brief A function used to check password.
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @param[in] password			Password to be checked.
     *
	 * @return                      TRUE when the password is usable.
	 */
    Boolean					(*checkPassword)(void *clientData, CFStringRef password);
 	/**
	 * @brief A function used to set password.
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @param[in] password			Password to be set to the epub file.
     *
	 * @return                      None.
	 */
    void					(*setPassword)(void *clientData, CFStringRef password);
	/**
	 * @brief A function used to set cipher.
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @param[in] cipher			The cipher used.
	 * @return None.
	 */
    void					(*setCipher)(void *clientData, FGSCipherFlag cipher);
	/**
	 * @brief A function used to set security handle.
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @param[in] security			Reference to a security object.
     *
	 * @return                      None.
	 */
    void					(*setSecurityHandle)(void *clientData, FGSEPUBSecurityRef security);
	/**
	 * @brief A function used to get encryption string when using standard security.
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @param[in] item				The item refer to FGSEPUBEncryptInfo.
     *
	 * @return					    The value of string got by the function, it is a string.
	 */
    CFStringRef             (*getEncryptionString)(void *clientData, UInt32 item);
	/**
	 * @brief A function used to verify the encryption.
	 * 
	 * @param[in] clientData		The user-supplied data.	
	 * @return                      TRUE when the encryption is usable.
	 */
    Boolean                 (*verifyEncryption)(void *clientData);
	/**
	* @brief A callback function can be called when to find a file in the ePub loaded.
	*
	* @param[in] clientData			The user-supplied data.
	* @param[in] fileName			The path of file in the ePub loaded.
    *
	* @return                       Reference to a ePub file.
	*/
    FGSEPUBFileRef			(*findFile)(void *clientData, CFStringRef fileName);
	/**
	* @brief A callback function can be called when to open an ePub file.
	*
	* @param[in] clientData			The user-supplied data.
	* @param[in] file   			Reference to a ePub file.
    *
	* @return					    Reference to a file stream.
	*/
    FGSFileStreamInRef      (*openFile)(void *clientData, FGSEPUBFileRef file);
	/**
	* @brief A callback function can be called when to close an ePub file created by OpenFile.
	*
	* @param[in] clientData			The user-supplied data.
	* @param[in] fileStream         The file stream created by openFile.
	*/
    void					(*closeFile)(void *clientData, FGSFileStreamInRef fileStream);
} FGSEPUBPackageHandler;

#if defined(__cplusplus)
}
#endif

#endif// __FGSEPUBBASE__

/** @} */

